package com.dp.appi.service.impl;

import com.dp.appi.dao.ExpCodesetDao;
import com.dp.appi.service.ExpCodesetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by xiaoji on 2016/5/14.
 */
@Service
public class ExpCodesetServiceImpl implements ExpCodesetService {
    @Autowired
    private ExpCodesetDao expCodesetDao;

    /**
     * 保存踏勘典设方案
     *  @param codeset_id     典设方案id
     * @param exploration_id 踏勘id
     */
    @Override
    public void saveExpCodeset(Long codeset_id, Long exploration_id) {
        expCodesetDao.saveExpCodeset(codeset_id,exploration_id);
    }

    /**
     * 重新计算汇总
     *
     * @param exploration_id 踏勘id
     */
    @Override
    public void updateExpCodeset(Long exploration_id) {
        expCodesetDao.updateExpCodeset(exploration_id);
    }

    /**
     * 踏勘典设导入模块
     *
     * @param module_id      模块id
     * @param exploration_id 踏勘id
     */
    @Override
    public void impExpModule(Long module_id, Long exploration_id) {
        Map<String,Object> map = expCodesetDao.getExpM(1,module_id,exploration_id);
        if(null == map) {
            expCodesetDao.impExpModule(module_id, exploration_id);
        }else {
            float num = Float.parseFloat(String.valueOf(map.get("n")));
            expCodesetDao.upExpMNum(num,1,module_id, exploration_id);
        }
    }

    /**
     * 踏勘典设导入材料
     *
     * @param material_id    材料id
     * @param exploration_id 踏勘id
     */
    @Override
    public void impExpMaterial(Long material_id, Long exploration_id) {
        Map<String,Object> map = expCodesetDao.getExpM(0,material_id,exploration_id);
        if(null == map) {
            expCodesetDao.impExpMaterial(material_id,exploration_id);
        }else {
            int num = Integer.valueOf(String.valueOf("1"));
            expCodesetDao.upExpMNum(num,0,material_id, exploration_id);
        }

    }

    /**
     * 修改踏勘典设材料数量
     *
     * @param id  模块id或者材料id
     * @param num
     */
    @Override
    public Long upExpMaterial(Long id, Integer num,Integer use_type) {
        return expCodesetDao.upExpMaterial(id,num,use_type);
    }

    /**
     * 删除踏勘典设材料
     *
     * @param id 模块id或者材料id
     */
    @Override
    public Long delExpMaterial(Long id) {
        return expCodesetDao.delExpMaterial(id);
    }

    /**
     * 获取保存的踏勘典设列表
     *
     * @param exploration_id
     * @return
     */
    @Override
    public List<Map<String, Object>> queryExpCodeset(Long exploration_id) {
        return expCodesetDao.queryExpCodeset(exploration_id);
    }

    public  String getReModule (Long module_id){
        return expCodesetDao.getReModule(module_id);
    }

    /**
     * 得到material
     * @param material_id
     * @return
     */
    public  String getReMaerial (Long material_id){
        return expCodesetDao.getReMaerial(material_id);
    }

    @Override
    public void upCodesetMaterial(Map<String, String> param) {
        expCodesetDao.upCodesetMaterial(param);
    }
}
